# include <stdio.h>
# include <string.h>
# include "Header.h"
# include "DirectoryOps.h"

int moveFile(char *srcPath, char *destPath, struct VFS *header, struct NArray_node *NArrayRoot) {
	char *data, *fileName, dest[100];
	char fName[50], fType[5];
	int i, j, ret = 0;
	for(i = 0; i < 100; i++) {
		dest[i] = '\0';	
	}
	copyString(dest, destPath);
	if(!searchNArrayNode(NArrayRoot, truncateRight(dest))) {
		return 1;
	}
	for (i = 0; i < MAX_FD_SIZE; i++) {
		if (header -> freeList[i]) {
			if (!strcmp(header -> fd[i].filePath, srcPath)) {
				copyString(header -> fd[i].filePath, destPath);
				fileName = getLastDir(destPath);
				j = 0;
				while(*(fileName + j) != '.') { //split fileName and fileType from full FileName
					fName[j] = *(fileName + j);
					j++;
				}	
				copyString (fType, (fileName + j + 1));
				copyString(header -> fd[i].fileName, fName);
				copyString(header -> fd[i].fileType, fType);
				return 2;
			}
		}
	}
	return 0;
}
